package translinkApp.Adaptors;

import java.util.ArrayList;

import translinkApp.Data.ResolvedLocation.ResolvedLocationList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;

public class LocationsAdapter extends BaseAdapter {

	private Context mContext;
	private ResolvedLocationList locations;
	public ArrayList<CheckBox> checkBoxes;

	public LocationsAdapter(Context c, ResolvedLocationList locations) {
		mContext = c;
		this.locations = locations;
		this.checkBoxes = new ArrayList<CheckBox>();
	}

	public int getCount() {
		return locations.size();
	}

	public Object getItem(int position) {
		return locations.get(position);
	}

	public long getItemId(int position) {
		return 0;
	}

	public boolean isChecked(int position) {
		return checkBoxes.get(position).isChecked();
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		CheckBox checkBox;
		if (convertView == null) {

			checkBox = new CheckBox(mContext);
			checkBoxes.add(checkBox);

		} else {
			checkBox = (CheckBox) convertView;
		}

		checkBox.setText(locations.get(position).getDisplayAddress());
		checkBox.setTag(locations.get(position));
		return checkBox;
	}
}